package Time;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;

public class LocalDateDemo1 {
    public static void main(String[] args) {

        //1.获取当前时间的日历对象(包含年月日)
        LocalDate nowDate = LocalDate.now();
        System.out.println(nowDate);//2024-08-12

        //2.获取指定的时间的日历对象
        LocalDate ldDate = LocalDate.of(2023, 2,1 );
        System.out.println(ldDate);//2023-01-01

        //3.get系列方法获取日历中的每一个属性值
        //获取年
        int year = nowDate.getYear();
        System.out.println(year);//2024

        //获取月
        //方式一:
        Month m = ldDate.getMonth( );  //Month对象,还有MonthDay对象，可以使用equals来判断是否相同
        System.out.println(m); //FEBRUARY
        System.out.println(m.getValue( ));//2
        //方式二:
        int month = ldDate.getMonthValue();
        System.out.println( "month: " + month);//2

        //获取日
        int day = ldDate.getDayOfMonth();
        System.out.println( "day: " + day) ;//day: 1
        //获取一年的第几天
        int dayofYear = ldDate.getDayOfYear( );
        System.out.println( "dayOfYear: " + dayofYear);//dayOfYear: 32
        //获取星期
        DayOfWeek dayofweek = ldDate.getDayOfWeek();
        System.out.println(dayofweek );//WEDNESDAY
        System.out.println(dayofweek.getValue( ));//3

        //is开头的方法表示判断
        System. out.println( ldDate.isBefore( nowDate));//true
        System.out.println( ldDate.isAfter(ldDate));//false

        //with开头的方法表示修改,只能修改年月日

        //minus开头的方法表示减少.只能减少年月日

        //plus开头的方法表示增加,只能增加年月日

    }
}
